<?php

use hhz\constant\redis\redisKeys;
use Biz\cache\album\AlbumListCache;
use Biz\model\Album\AlbumListModel;
use Biz\service\Album\SyncEsMainContentService;
use Doraemon\tools\Log;
use Hhz\Redis\newCache;

class AlbumCacheAction extends ActionPlugin
{
    const IS_TRACING = true;

    /**
     * @throws Exception
     */
    public function main()
    {
        $message = $this->messageBody;
        $table = $this->messageBody['table'] ?? '';
        $uid = 0;
        if (strstr($table, AlbumListModel::_TABLE_NAME)) {
            $data = $this->messageBody['data'] ?? [];
            $albumId = $data['album_id'] ?? '';
            if ($data && $albumId) {
                $newRedis = new newCache(redisKeys::KEY_B_CACHE_ALBUM_LIST);
                if(AlbumListModel::STATUS_DELETE == $data['status']){
                    $newRedis->delCache($albumId);
                }else{
                    $newRedis->setCaches([$albumId => $data]);
                }
                //更新清单在maincontent es索引里面的数据
                $res = SyncEsMainContentService::syncAlbumToEsMainContent($albumId,$data);
                Log::info('更新清单在maincontent es索引里面的数据',['$res'=>$res]);
            }
        }
        Log::info('接收到事件消息#uid:' . $uid, compact('uid', 'message'));
        $this->setSuccess();
    }
}